package com.mybatis;
import com.mybatis.mapper.WorkerMapper;
import com.mybatis.pojo.Worker;
import com.mybatis.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
public class Part20 {
    public static void findWorkerByIdTest() {
        // 1.通过工具类获取SqlSession对象
        SqlSession session = MyBatisUtils.getSession();
        WorkerMapper mapper = session.getMapper(WorkerMapper.class);
        // 2.使用WorkerMapper对象查询id为1的员工的信息
        Worker worker = mapper.selectWorker(1);
        System.out.println(worker.toString());
        // 3.关闭SqlSession
        session.close();
    }
    public static void insertWorkerTest() {
        // 1.通过工具类生成SqlSession对象
        SqlSession session = MyBatisUtils.getSession();
        Worker worker = new Worker();
        worker.setId(4);
        worker.setName("赵六");
        worker.setAge(36);
        worker.setSex("女");
        worker.setWorker_id(Integer.parseInt("1004"));
        WorkerMapper mapper = session.getMapper(WorkerMapper.class);
        // 2.插入员工信息
        int result = mapper.insertWorker(worker);
        if (result > 0) {
            System.out.println("成功插入" + result + "条数据");
        } else {
            System.out.println("插入数据失败");
        }
        System.out.println(worker.toString());
        session.commit();
        // 3.关闭SqlSession
        session.close();
    }
    public static void main(String[] args){
        findWorkerByIdTest();
        insertWorkerTest();
    }
}

